<!DOCTYPE html>
<html lang="zh-cn"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/main.css" rel="stylesheet">

    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico" />

    <title>efi和grub2相关配置文件及命令 | wiseAI的小站</title>
</head><body><div class="container-fluid">
    <nav class="navbar fixed-top navbar-expand-sm navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <img src="/img/favicon.ico" alt="" width="30" height="24" class="d-inline-block align-text-top">
                wiseAI的小站
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/articles/">文章</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/categories/">分类</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/tags/">关键字</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/post/golang/">golang编程</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/about/">关于</a>
                    </li>
                    
                </ul>
                <form class="d-flex">
                    <input id="search-query" class="form-control me-2" type="search" placeholder="Search for anything..." aria-label="Search">
                </form>
            </div>
        </div>
    </nav>
</div>




<div id="content">
<div class="container article">
	<h1>efi和grub2相关配置文件及命令</h1>
	<div class="post-meta">
		<div>
			
			
			By wiseai | 2022-05-30 | 1 minutes
		</div>
		<div class="tags">
			
			<a class="btn btn-light links btn-sm" href="/tags/%E7%B3%BB%E7%BB%9F%E5%BC%95%E5%AF%BC/">系统引导</a>
			
			<a class="btn btn-light links btn-sm" href="/tags/%E5%90%AF%E5%8A%A8/">启动</a>
			
		</div>
	</div>
	<div>
		<div class="article-post">
			<h3 id="一配置文件目录">一、配置文件目录</h3>
<p>/etc/grub2/目录下
/etc/default/grub</p>
<h3 id="二更新引导项目">二、更新引导项目</h3>
<p>根据配置文件目录下的顺序更新启动项，命令：</p>
<p><code># grub2-mkconfig -o /boot/grub2/grub.cfg</code></p>
<p>-o 选项为输出到那个文件</p>
<p>efi下的/boot/efi/EFI/centos/grub.cfg文件一般调用/boot/grub2/grub.cfg这个文件</p>
<p>类debian发行版，一般用这个命令：
<code># update-grub2</code></p>
<h3 id="三更换默认启动项">三、更换默认启动项</h3>
<p>命令：</p>
<p><code># grub2-set-default 2</code></p>
<p>一般从0开始</p>
<h3 id="四安装">四、安装</h3>
<p><code># grub-install --efi-directory=/boot/efi/ --boot-directory=/boot/ --removable /dev/sda</code>
几个需要说明的地方：</p>
<blockquote>
<p><code>--efi-directory=/boot/efi/</code>这个位置的问题，如果efi分区是单独挂载的，就直接写这个目录就可以了，不用加efi，它会在这个目录下建立EFI的目录，写入相关文件。
<code>--boot-directory=/boot/</code>这个不用加grub2，它会自己生成grub2目录，写入相关文件
<code>--removable</code>如果是移动设备，一定要加这个选项</p>
</blockquote>
<h3 id="五常用命令">五、常用命令</h3>
<ul>
<li>启动常用的grub命令</li>
</ul>
<pre tabindex="0"><code>root (hd0,2)          #设置某块分区为根目录
kernel /vmlinuz       #加载linux kernel
initrd /initrd.gz     #加载驱动，或者虚拟rootfs
boot                  #启动加载的kernel
</code></pre><ul>
<li>查找文件
<code>find --set-root --ignore-floppies --ignore-cd /usr/bin/cp   #查找/usr/bin/cp文件，并将分区设为根目录，忽略软盘和cd</code></li>
<li>加载iso</li>
</ul>
<pre tabindex="0"><code>root (hdx,x)                    #设置根目录
map --mem /xx.iso (0xff)        #映射iso文件到模拟cdrom 0xff
map --hook                      #映射钩子
chainloader (0xff)              #链接到映射的CDROM
boot                            #启动
</code></pre><p>grub命名规则，(hd32)为第一仿真cd/dvd设备，等同于0xa0，(hd33)为二仿真cd/dvd设备，0xff为最后一个。grub中将0xa0以上都认做cdrom。
<code>map --mem</code> 用于仿真不连续的存放的iso文件，不加则必须连续存放，碎片整理后再存放iso一般才会连续。
另外grub不支持大的iso，如果iso不支持则提示:inviladorupsupported executableformat。</p>
<h3 id="六添加efi启动项">六、添加efi启动项</h3>
<p>在安装程序不完善的时候，有时候会存在没有启动项的问题，这个时候就要用efibootmgr管理UEFI启动项。
<code># efibootmgr</code>
这个命令会显示所有已经添加的启动项，BootOrder后会显示启动顺序。
<code># efibootmgr -c -w -L &quot;BootOptionName&quot; -d /dev/sda -p 1 -l \\EFI\\UOS\\grubx64.efi</code>
BootOptionName是你启动项的名字，修改为自己的
-d修改那个硬盘
-p分区位置，默认为1
-l是启动efi文件的路径，注意是\而不是//
这样就添加了EFI启动项，刚添加的启动项的顺序排第一个
<code># efibootmgr -b 0013 -B</code>
删除编号为0013的启动项
<code># efibootmgr -o 0012,0010,000f</code>
修改启动顺序。
这个命令没有认真研究，有空再说吧。</p>
<h3 id="七需要注意的地方">七、需要注意的地方</h3>
<pre><code>grub背景图片的问题，最近用gimp做了个图片设为grub2启动背景图片，grub2提示错误，最后发现是图片的问题。</code></pre>

		</div>
	</div>
</div>


<div class="container">
    
    <div class="row">
        
        <div class="col-5">
            <a class="page-link link-dark text-end dh" href="/post/filebrowser%E7%9A%84%E5%AE%89%E8%A3%85%E5%92%8C%E4%BD%BF%E7%94%A8/">
                <h5>前一篇</h5><br>
                filebrowser的安装和使用
            </a>            
        </div>
        
        <div class="col-2">
        </div>
        
        <div class="col-5">
            <a class="page-link link-dark text-start dh" href="/post/docker%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">
                <h5>后一篇</h5><br>
                docker学习笔记
            </a>            
        </div>
        
    </div>
    
</div>

        </div><br><br>
<footer class="container">
    <h2>友情链接</h2>
    <hr>
    <nav class="nav nav-pills flex-column flex-sm-row">
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/gnzg/index.html" target="_blank">孤鸟之歌</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/mm/index.html" target="_blank">生成随机字符</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/md/index.html" target="_blank">MarkDown</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/" target="_blank">Gitee</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://github.com/" target="_blank">Github</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyun.com/" target="_blank">阿里云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cloud.tencent.com/" target="_blank">腾讯云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.oschina.net/" target="_blank">OSCHINA开源中国</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/wiseai/the-way-to-go_ZH_CN/blob/master/eBook/directory.md" target="_blank">the way to go</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://topgoer.com/" target="_blank">golang文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://goframe.org/display/gf" target="_blank">GoFrame</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyundrive.com/" target="_blank">阿里云盘</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cn.vuejs.org/" target="_blank">vue3文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://element-plus.gitee.io/zh-CN/" target="_blank">element-plus文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.runoob.com/vue3/vue3-tutorial.html" target="_blank">vue3菜鸟教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://v5.bootcss.com/" target="_blank">bootstrap v5 中文文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.bootstrap.cn/" target="_blank">bootstrap文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://caddy2.dengxiaolong.com/docs/" target="_blank">caddy中文教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.58pic.com/" target="_blank">千图</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://ifonts.com/" target="_blank">iFonts</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://marketing.qiniu.com/" target="_blank">七牛云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.ixigua.com/" target="_blank">西瓜视频</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/yugang/index.html" target="_blank">鱼缸计算</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://justcc.mengkang.net/#/" target="_blank">C语言JustCC</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/pptist/" target="_blank">PPTist</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="/index.xml" target="_blank">RSS</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.kancloud.cn/idcpj/python/418553" target="_blank">参考资料</a>
        
    </nav>

    <div class="copyright text-center">
      <span class="power-by">
        Powered by <a class="links" href="https://gohugo.io" target="_blank">Hugo</a>
    </span>
    <span>|</span>
    <span>
        Theme - <a class="links" href="https://github.com/wiseai-go/blog-hugo" target="_blank">WiseAI</a>
    </span>
    <br>
    <span class="copyright-year">
        &copy;
        
        2017 -
        2023<span>
            陇ICP备15000157号
            
        </span></span>

</div>
</footer>
<script src="/js/bootstrap.bundle.min.js"></script>


</body>
</html>
